Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using distutils #2564

Closed
wants to merge 1 commit into from

Conversation

s-t-e-v-e-n-k
Copy link
Contributor

distutils is due to be removed in Python 3.12, but even so we don't need to use it, since the sysconfig module can handle our use-cases just fine for all supported Python versions.

Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

@xrmx
Copy link
Collaborator

xrmx commented Oct 3, 2023

Thanks for the pr, care to keep 2.7 compat?

@s-t-e-v-e-n-k
Copy link
Contributor Author

Based on https://docs.python.org/2.7/library/sysconfig.html , it is 2.7 compatible? The CI fail looks unrelated:

Python 2.7.18
In file included from plugins/python/python_plugin.c:1:
plugins/python/uwsgi_python.h:4:10: fatal error: Python.h: No such file or directory
   4 | #include <Python.h>

@xrmx
Copy link
Collaborator

xrmx commented Oct 3, 2023

Based on https://docs.python.org/2.7/library/sysconfig.html , it is 2.7 compatible? The CI fail looks unrelated:

Python 2.7.18
In file included from plugins/python/python_plugin.c:1:
plugins/python/uwsgi_python.h:4:10: fatal error: Python.h: No such file or directory
   4 | #include <Python.h>

You changed the search paths for includes, i guess sysconfig and distutils.sysconfig does not return the expected paths on python 2.7

@terencehonles terencehonles mentioned this pull request Oct 3, 2023
Copy link
Contributor

@terencehonles terencehonles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're picking the wrong path for the second call, but I think there's something wrong (different) with the include paths that are built and the actual system. I printed the difference between the two methods here https://github.com/unbit/uwsgi/actions/runs/6398069839/job/17367389012?pr=2567#step:8:13 and you can see that the newer call returns a /usr/local/ path for the includes.

plugins/asyncio/uwsgiplugin.py Outdated Show resolved Hide resolved
@s-t-e-v-e-n-k
Copy link
Contributor Author

I clearly latched onto platform-specific files in the docs, without considering it was for header files, nice catch!

distutils is due to be removed in Python 3.12, but even so we don't need
to use it, since the sysconfig module can handle our use-cases just fine
for all supported Python versions.
Copy link
Contributor

@terencehonles terencehonles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like debian has the following patch https://salsa.debian.org/cpython-team/python2/-/blob/2.7.18-12/debian/patches/distutils-install-layout.diff which is breaking this. You could specify PYTHONUSERBASE=1 to bypass the bug, but this looks like it will break other users if you did that to pass the tests.

You could handle it with the following suggestion (I've tested it with #2567), which you can pull into your branch by creating PR s-t-e-v-e-n-k/uwsgi@no-more-distutils...terencehonles:uwsgi:pr-2564-patch and merging it (which will update this PR).

However, this may break on Python 3.12 (which currently doesn't build) because if that patch still applies to Python 3, distutils is no longer included, and the path is still wrong, the include path will not be set correctly.

@@ -1,10 +1,10 @@
from distutils import sysconfig
import sysconfig
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import sysconfig
import os
import sysconfig
def get_includes():
try:
from distutils import sysconfig as legacy
except ImportError:
legacy = None
yield sysconfig.get_path('include')
yield sysconfig.get_path('platinclude')
if legacy:
yield legacy.get_python_inc()
yield legacy.get_python_inc(plat_specific=True)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sysconfig.get_path also allows us to specify which scheme we want with the second argument, rather than what you've done here. However, I'm loathe to check if 'deb_system' is a suitable scheme, but this only appears to rear it's head on Python 2, rather than every version of Python 3 that also ships distutils.

barriere% python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/include/python3.9'
>>> 
barriere% python2 
Python 2.7.18 (default, Jul 14 2021, 08:11:37) 
[GCC 10.2.1 20210110] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_path('include')
'/usr/local/include/python2.7'
>>> sysconfig.get_path('include', 'deb_system')
'/usr/include/python2.7'

Comment on lines +6 to +7
'-I' + sysconfig.get_path('include'),
'-I' + sysconfig.get_path('platinclude')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'-I' + sysconfig.get_path('include'),
'-I' + sysconfig.get_path('platinclude')
'-I' + i for i in filter(os.path.exists, get_includes()),

@xrmx
Copy link
Collaborator

xrmx commented Oct 6, 2023

Merged a modified version in #2570

@xrmx xrmx closed this Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants